<template>
	<view class="page">
		<image :src="storeInfo.logo_img" mode=""></image>
		<view class="markAddress">
			<view class="title1">
				<view class="title1Item1">
					{{storeInfo.name}}
				</view>
				<view class="title1Item2" @click="savePaySort">
					帮他靠前
				</view>
			</view>
			<view class="time">
				营业时间：{{storeInfo.online_time}}
			</view>

			<view class="introduction">
				<view class="">
					{{storeInfo.introduce}}
				</view>
				<view class="more">
					>
				</view>
			</view>
			<view class="phone">
				<view class="">
					古玩地摊服务电话
				</view>
				<view class="phone1">
					一件拨打>
				</view>
			</view>
			<view class="total">

				<view class="title">
					<view class="totalItem">

					</view>
					全部商户
				</view>
				<view class="more">
					更多>
				</view>
			</view>
			<view class="businesses" v-for="item in storeList" @click="gotoStore(item)">
				<image :src="item.logo_img" mode=""></image>
				<view class="title">
					<view class="title1">
						{{item.store_name}}
					</view>
					<view class="address">
						{{item.introduce}}
					</view>
					<!-- <view class="title3">
						距离古玩地毯6.9km
					</view> -->
				</view>
			</view>





		</view>
		<!-- 弹框 -->

		<u-popup :show="showPaymentDialog" mode="center">
			<view class="popup-content">

				<image style="width: 200rpx;height: 200rpx;"
					src="http://140.143.146.33/wxImg/static/wx_pay.png" mode="">
				</image>

				<view class="popup-title">发到手机微信支付</view>
				<view class="popup-description">请确认支付金额</view>
				<view class="popup-amount">金额：{{ amount }} 元</view>
				<view class="payment" @click="initiatePayment">二维码支付</view>
				<view class="cancel" @click="closeDialog">取消</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		getStoreListById,
		savePaySort,
		delNameById,
		getLSpaySort
	} from '@/config/api.js';
	export default {
		data() {
			return {
				
				queryList:{
					navId: null,
					markId: null,
					page: 1,
					limit: 20
				},
				showPaymentDialog: false, // 控制弹框显示
				amount: 100, // 支付金额，可以根据需要进行动态设置
				storeInfo: {},
				storeList: [],
			}
		},
		onLoad(options) {
			console.log(options,'=======')
			// 获取传递的标题
			if (options.title) {
				this.title = decodeURIComponent(options.title); // 解码并设置标题
				uni.setNavigationBarTitle({
					title: this.title // 设置导航栏标题
				});
				this.queryList.navId = options.navId;
				this.queryList.markId = options.markId;
				this.markListById();
			}
		},
		methods: {
			savePaySort(){
				const _this = this;
				uni.showModal({
					title: '确认付费提升排名？',
					success: function(res) {
						if (res.confirm) {
							getLSpaySort({
								nav_id: _this.queryList.navId
							}).then(data => {
								if(data.signType){
									wx.requestPayment({
									  timeStamp: data.timeStamp,
									  nonceStr: data.nonceStr,
									  package: data.package,
									  signType: data.signType,
									  paySign: data.paySign,
									  success (res) { 
										  savePaySort({
											  market_id: _this.queryList.markId,
											  nav_id: _this.queryList.navId
										  }).then(res => {
											  console.log(res,'=============')
											  uni.$u.toast('操作成功!')
										  })
									  },
									  fail (res) { 
										  // 支付失败 删除商品
										  delNameById({order_sn: data._order_sn})
									  }
									})
								}
							})
						}
					}
				});
			},
			gotoStore(item){
				uni.navigateTo({
					url: `/moduleA/storeList/markAddress?title=${encodeURIComponent(item.store_name)}&storeId=${item.id}&navId=${this.queryList.navId}&markId=${this.queryList.markId}`,
				});
			},
			markListById(){
				getStoreListById(this.queryList).then(res => {
					this.storeInfo = res.storeInfo;
					this.storeList = res.data;
				})
			},
			//微信支付
			openPaymentDialog() {
				
				
				console.log('888888');
				this.showPaymentDialog = true; // 显示支付弹框
			},
			closeDialog() {
				this.showPaymentDialog = false; // 关闭支付弹框
			},
			initiatePayment() {
				// 调用微信支付接口，假设你的后端返回了需要的支付参数
				const paymentData = {
					timeStamp: '1234567890', // 时间戳
					nonceStr: 'abc123', // 随机字符串
					package: 'prepay_id=wx1234567890', // 预支付交易会话标识
					signType: 'MD5', // 签名方式
					paySign: 'abcdefg1234567', // 签名
				};

				uni.requestPayment({
					...paymentData,
					success: (res) => {
						uni.showToast({
							title: '支付成功',
							icon: 'success',
						});
						this.closeDialog(); // 关闭弹框
					},
					fail: (err) => {
						uni.showToast({
							title: '支付失败',
							icon: 'none',
						});
						console.error(err);
					},
				});
			},

		}
	}
</script>


<style scoped lang="scss">
	@import 'markAddress.scss';

	.popup-content {
		padding: 20px;
		text-align: center;
	}

	.popup-title {
		font-size: 18px;
		font-weight: bold;
	}

	.popup-description {
		margin: 10px 0;
	}

	.popup-amount {
		font-size: 16px;
		color: #333;
		margin-bottom: 20px;
	}

	.payment {
		width: 500rpx;
		height: 80rpx;
		line-height: 80rpx;
		color: #fff;
		background-color: springgreen;
	}

	.cancel {
		width: 500rpx;
		height: 80rpx;
		line-height: 80rpx;

	}
</style>